package com.util.result;

import lombok.Getter;
import lombok.Setter;

/**
 * @Description 请求响应体
 * @Author zhu_js
 * @Date 2020/4/14 20:26
 * @Version 1.0
 */
@Getter
@Setter
public class Message<T>{
    String code;
    String message;
    T data;

    public Message(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public Message(String code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * 操作成功
     * @return
     */
    public static Message success() {
        return new Message<>("00", "操作成功");
    }

    public static <T> Message<T> success(T data) {
        return new Message<>("00", "操作成功", data);
    }

    public static <T> Message success(String message) {
        return new Message<>("00", message);
    }

    public static Message success(String code, String message) {
        return new Message(code, message);
    }

    public static <T> Message success(String code, String message, T data) {
        return new Message<>(code, message, data);
    }

    /**
     * 操作失败
     * @return
     */
    public static Message error() {
        return new Message("B0", "操作失败");
    }

    public static <T> Message error(T data) {
        return new Message<>("B0", "操作失败", data);
    }
    public static <T> Message error(String message) {
        return new Message<>("B0", message);
    }

    public static Message error(String code, String message) {
        return new Message(code, message);
    }

    public static <T> Message<T> error(String code, String message, T data) {
        return new Message<>(code, message, data);
    }
}
